#include<algorithm>
#include<cstdio>
#include<map>
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
struct school{
    string name;
    double score;
    int num;
    school(string name,double score,int num):name(name),score(score),num(num){}
};
bool cmp(school a,school b){
    if(a.score!=b.score)return a.score>b.score;
    if(a.num!=b.num)return a.num<b.num;
    if(a.name!=b.name)return a.name<b.name;
}
map<string,int> name2seq;
int seq=0;
int findseq(string name){
    if(name2seq.find(name)==name2seq.end()){
        name2seq[name]=seq++;
    }
    return name2seq[name];
}

int main(){
    //freopen("in.txt","r",stdin);
    int N;
    scanf("%d",&N);
    vector<school> sch;
    string id,name;
    double score;
    int seq;
    for(int i=0;i<N;i++){
        cin>>id>>score>>name;
        transform(name.begin(),name.end(),name.begin(),::tolower);
        if(id[0]=='A'){score=score;}
        else if(id[0]=='B'){score=score*1.0/1.5;}
        else if(id[0]=='T'){score=score*1.5;}
        seq=findseq(name);
        if(seq==sch.size()){sch.push_back(school{name,score,1});}
        else{
            sch[seq].score+=score;
            sch[seq].num++;
        }
    }
  	for(int i=0;i<sch.size();i++){
      sch[i].score=(int)sch[i].score;
    }
    sort(sch.begin(),sch.end(),cmp);
    seq=0;
    printf("%d\n",sch.size());
    for(int i=0;i<sch.size();i++){
        if(i>0 && sch[i].score==sch[i-1].score){
            seq--;
        }
        else{seq=0;}
        cout<<seq+i+1<<" "<<sch[i].name<<" "<<sch[i].score<<" "<<sch[i].num<<endl;
    }
}
